﻿using System;
using System.Collections.Generic;
using Battle.Engine.LogicModel;

namespace Battle.Engine.AI
{
    public class EngineAIReplay : EngineAI
    {
        FOperateTrans trans = null;
        List<FOperateSkill> skills = null;

        Queue<FOperateSkill> curRoundSkills = null;

        void init()
        {

        }

        public override void Start(EngineData data, CampType camp, BaseCompute engine)
        {
            base.Start(data, camp, engine);
            curRoundSkills = new Queue<FOperateSkill>();
        }

        public override void Run()
        {
            if (isRunning == true)
                return;
            isRunning = true;

            base.Run();

            //得带当前回合需要释放的技能
            if (skills != null)
            {
                curRoundSkills.Clear();
                foreach (FOperateSkill op in skills)
                {
                    if (op.camp == data.curRoundCamp && op.round == data.roundNum)
                    {
                        curRoundSkills.Enqueue(op);
                    }
                }
            }

            //是否需要换阵
            if (trans != null)
            {
                if (trans.round == data.roundNum)
                {
                    data.compute.DoTrans(trans.uids, trans.fpids);
                }
            }
        }

        public override void Update(double deltaTime)
        {
            if (isRunning == false)
                return;

            for (int i = 0; i < 100; ++i)
            {
                FOperateSkill op = curRoundSkills.Peek();
                if (op == null)
                    break;
                if (op.roundTime >= data.roundTime)
                {
                    data.compute.DoSkill(op.camp, op.uniquedId, op.skillIndex);
                    curRoundSkills.Dequeue();
                }
            }

            if (curRoundSkills.Count == 0)
            {
                if (data.compute.HasActiveNormalSkill() == false && data.ultimateSkill == null)
                {
                    data.compute.FinishRound();
                    return;
                }
            }
        }
    }
}
